package com.hxd.buybooksystem.adapter

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.UpdateListener
import com.hjq.image.ImageLoader
import com.hxd.buybooksystem.R
import com.hxd.buybooksystem.bean.BookInfo
import com.hxd.buybooksystem.bean.Order

/**
 *  项目名：    BuyBookSystem
 *  包名：      com.hxd.buybooksystem.adapter
 *  文件名:     BuyCarOrderAdapter
 *  创建者:     HXD
 *  创建时间:   2019/6/2 15:46
 *  描述:       历史订单数据适配
 */

class HistoryOrderAdapter(private val datas:ArrayList<Order>) : RecyclerView.Adapter<HistoryOrderAdapter.ViewHolder>(){

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_historyorder, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return datas.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val orderItem = datas[position]
        if(orderItem.isPay){
            ImageLoader.loadImage(holder.image, orderItem.image)
            holder.name.text = orderItem.name
            holder.price.text = orderItem.price
            holder.buyCount.text = orderItem.buyCount.toString()
            holder.ordertime.text = orderItem.createdAt
        }
    }

    /**
     * RecyclerView的持有者类
     */
    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var image: ImageView = view.findViewById(R.id.iv_image_history_order)
        var name: TextView = view.findViewById(R.id.tv_name_history_order)
        var price: TextView = view.findViewById(R.id.tv_price_history_order)
        var buyCount: TextView = view.findViewById(R.id.tv_buyCount_history_order)
        var ordertime: TextView = view.findViewById(R.id.tv_history_orderTime_history_order)
    }

}